ccR.Monk = {
	Chi_Builder =
	function(health)
		if health == nil then health = 99 end
		if ccR.Player.Specialization() == 1
		and ccR.Spell.CanAttack(KEG_SMASH)
		and ccR.Player.Is.Facing("target")
		and ccR.Player.Chi() < (ccR.Player.MaxChi()-3)
		then
			ccR.Cast.Attack(KEG_SMASH)
		elseif ccR.Player.Health() <= health 
		and ccR.Player.Count(10) > 0 
		and ccR.Spell.Is.Ready(EXPEL_HARM)
		then
			if ccR.Player.Is.CastingOrChanneling() then SpellStopCasting() end
			ccR.Cast.Spell(EXPEL_HARM)
		elseif ccR.Spell.Is.Ready(SPINNING_CRANE_KICK)
		and not ccR.Player.Has.Talent(RUSHING_JADE_WIND)
		and ccR.Player.Count(8) >= 3
		then
			ccR.Cast(SPINNING_CRANE_KICK)
		elseif ccR.Spell.CanAttack(JAB)
		and ccR.Player.IsFacing("target")
		then
			ccR.Cast.Attack(JAB) 
		end
	end,
	Spinning_Crane_Kick = 
	function(count)
		if count == nil then count = 3 end
		if ccR.Spell.Is.Ready(SPINNING_CRANE_KICK) 
		and not ccR.Player.Has.Talent(RUSHING_JADE_WIND) 
		and ccR.Player.Count(8) >= count 
		then 
			ccR.Cast.Spell(SPINNING_CRANE_KICK)
		end
	end,
}
setmetatable(ccR.Monk, ccR)

ccR.Monk.Features = {
	Fortifying_Brew = function(health) if health == nil then health = 60 end if ccR.Spell.IsReady(FORTIFYING_BREW) and ccR.Player.Health() <= health then ccR.Cast.Spell(FORTIFYING_BREW) end end,
	Nimble_Brew = function() if ccR.Spell.IsReady(NIMBLE_BREW) then local eventIndex = C_LossOfControl.GetNumEvents() while (eventIndex > 0) do local _, _, text = C_LossOfControl.GetEventInfo(eventIndex)	if text == LOSS_OF_CONTROL_DISPLAY_ROOT or text == LOSS_OF_CONTROL_DISPLAY_SNARE or text == LOSS_OF_CONTROL_DISPLAY_STUN_MECHANIC or text == LOSS_OF_CONTROL_DISPLAY_STUN or text == LOSS_OF_CONTROL_DISPLAY_FEAR or text == LOSS_OF_CONTROL_DISPLAY_HORROR then ccR.Cast.Spell(NIMBLE_BREW) return end eventIndex = eventIndex - 1 end end end,
	Touch_of_Karma = function(health) if health == nil then health = 80 end if ccR.Spell.CanAttack(TOUCH_OF_KARMA) and ccR.Player.Health() <= health then ccR.Cast.Spell(TOUCH_OF_KARMA) end end,
	Spear_Hand_Strike = function(time) if time == nil then time = 1 end if ccR.Spell.CanAttack(SPEAR_HAND_STRIKE) then if ccR.Target.IsCastingOrChanneling() then if ccR.Target.IsCasting() and ccR.Target.HasLeftOnCast(time) then ccR.Cast.Attack(SPEAR_HAND_STRIKE) end if ccR.Target.IsChanneling() then ccR.Cast.Attack(SPEAR_HAND_STRIKE) end end end end,
	Detox =
	function()
		if ccR.Spell.IsReady(DETOX) then
			for i = 1, 40 do
				local name, _, _, _, debuffType = UnitDebuff("player", i) 
				-- No debuff found, Exit the check
				if name == nil then
					break
				else
					-- Found a debuff, Check if Poison or Disease
					if debuffType == "Poison"
					or debuffType == "Disease"
					then
						ccR.Cast.Spell(DETOX, "player")
						return
					end
				end
			end
		end
	end,
	Legacy_of_the_White_Tiger =	
	function() 
		if ccR.Spell.Is.Ready(LEGACY_OF_THE_WHITE_TIGER)
		and not ccR.Player.Has.Buff(MARK_OF_THE_WILD)
		and not ccR.Player.Has.Buff(BARK_OF_THE_WILD)
		and not ccR.Player.Has.Buff(BLESSING_OF_KONGS)
		and not ccR.Player.Has.Buff(EMBRACE_OF_THE_SHALE_SPIDER)
		and not ccR.Player.Has.Buff(STRENGTH_OF_THE_EARTH)
		and not ccR.Player.Has.Buff(LEGACY_OF_THE_WHITE_TIGER)
		and not ccR.Player.Has.Buff(LEGACY_OF_THE_EMPEROR) 
		and not ccR.Player.Has.Buff(BLESSING_OF_KINGS) 
		then
			ccR.Cast.Spell(LEGACY_OF_THE_WHITE_TIGER)	
		end
	end,
	Touch_of_Death = 
	function()
		if ccR.Spell.CanAttack(TOUCH_OF_DEATH) 
		and (
				(not ccR.Target.Is.Boss() and UnitHealth("target") < UnitHealthMax("player"))
				or 
				(ccR.Target.Is.Boss() and ccR.Target.Health() <= 10)
			) 
		and ccR.Player.Is.Facing("target") 
		and not UnitIsPlayer("target") 
		then
		 	ccR.Cast.Attack(TOUCH_OF_DEATH) 
		end 
	end,
}
setmetatable(ccR.Monk.Features, ccR.Monk)